package com.example.controller;

import com.example.common.Result;
import com.example.entity.Shuju;
import com.example.service.ShujuService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 食材库存信息(Shuju)表控制层
 *
 */
@RestController
public class ShujuController {
    @Resource
    private ShujuService shujuService;

    //信息列表
    @ResponseBody
    @RequestMapping("shujuList")
    public Result shujuList(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum, 
                           @RequestParam(defaultValue = "1", value = "pageSize") Integer pageSize, 
                           HttpServletRequest request) {
        String key = request.getParameter("key");
        PageInfo<Shuju> pageInfo = shujuService.getShujuList(pageNum, pageSize, key);
        return Result.success(pageInfo);
    }
    
    //添加或编辑信息
    @ResponseBody
    @RequestMapping("shujuAdd")
    public Result shujuAdd(Shuju shuju, HttpServletRequest request) {
        shujuService.saveOrUpdate(shuju);
        return Result.success();
    }
    
    //删除信息
    @ResponseBody
    @RequestMapping("shujuDel")
    public Result shujuDel(int id, HttpServletRequest request) {
        shujuService.deleteShuju(id);
        return Result.success();
    }
    
    //批量删除信息
    @ResponseBody
    @RequestMapping("shujuDeleteAll")
    public Result typeDeleteAll(HttpServletRequest request) {
        String vals = request.getParameter("vals");
        shujuService.batchDeleteShuju(vals);
        return Result.success();
    }
}

